package limiter

import (
	"sync"
	"time"
)

type taskLimiter struct {
	tasks    	 map[string]taskInfo
	taskRunKey   chan int
	lock         *sync.RWMutex
	cap          int
}

type taskInfo interface {
	GetType () string
	GetUser () string
	GetUuid () string
	GetId () string
	GetNumber () int
	GetStatus()  string
	GetUsedTime () time.Duration
	GetWaitingTime () time.Duration
}

func (this *taskLimiter) AddTask (taskInfo taskInfo) {
	this.lock.Lock()
	defer this.lock.Unlock()
	this.tasks[taskInfo.GetUuid()] = taskInfo
}

func (this *taskLimiter) DeleteTask (uuid string) {
	this.lock.Lock()
	defer this.lock.Unlock()
	delete(this.tasks, uuid)
}

func (this *taskLimiter) UpdateTask (uuid string, taskInfo taskInfo) {
	this.lock.Lock()
	defer this.lock.Unlock()
	this.tasks[uuid] = taskInfo
}